package com.cristina.attention.handler.heartbeat;

import com.cristina.attention.codec.Invocation;
import com.cristina.attention.message.heartbeat.HeartbeatRequest;
import com.cristina.attention.message.heartbeat.HeartbeatResponse;
import com.cristina.attention.dispatcher.MessageHandler;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Author superman
 * @Date 2021/10/7 18:53
 **/
@Component
@Slf4j
public class HeartbeatRequestHandler implements MessageHandler<HeartbeatRequest> {

    @Override
    public void execute(Channel channel, HeartbeatRequest message) {
        log.debug("收到连接 {} 的心跳请求", channel.id());
        HeartbeatResponse response = new HeartbeatResponse();
        channel.writeAndFlush(new Invocation(HeartbeatResponse.TYPE, response));
    }

    @Override
    public String getType() {
        return HeartbeatRequest.TYPE;
    }
}
